import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isToBuy: false,
    cartList: [],
    Title: false, // 控制 Title 组件的显示与隐藏
    TitleTxt: '',
    Toast: false, // 控制 Toast
    PwdToast: false,
    infoToast: false
  },
  getters: {},
  mutations: {
    // 修改购物状态的方法
    changeBuyShow(state, payload) {
      state.isToBuy = payload
    },
    addToCart(state, payload) {
      state.cartList.push(payload);
    },
    // 打开itle组件
    openTitle(state, playload) {
      state.Title = true
      state.TitleTxt = playload
    },
    // 关闭 Title 
    closeTitle(state) {
      state.Title = false
    },
    // 打开 toast
    openToast(state) {
      state.Toast = true
    },
    // 打开 toast
    openToast(state) {
      state.Toast = true
    },
    // 关闭 toast
    closeToast(state) {
      state.Toast = false
    },
    openPwdToast(state) {
      state.PwdToast = true
    },
    closePwdToast(state) {
      state.PwdToast = false
    },
    closeInfoToast(state) {
      state.infoToast = false
    },
    openInfoToast(state) {
      state.infoToast = true
    }
  },
  actions: {
    // 两秒后 关闭 Title
    ToggleTitle(context) {
      setTimeout(() => {
        console.log(this)
        context.commit('closeTitle', false)
      }, 2000)
    }
  },
  modules: {}
})